package com.yanqu.road.web.timer;

import com.yanqu.road.utils.LocalDateTimeHelper;
import com.yanqu.road.utils.executor.GeneralTask;
import com.yanqu.road.web.mgr.ActivityMallMgr;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ActivityMallReloadTask extends GeneralTask {

    private Logger logger = LogManager.getLogger(this.getClass().getName());

    private long lastLoadTime = LocalDateTimeHelper.getZeroTimeTimeStamp();

    private boolean isRun = false;

    @Override
    public void doRun() {
        //每天重新加载活动
        long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp();
        if(lastLoadTime < zeroTime && !isRun){
            isRun = true;
            try {
                ActivityMallMgr.reloadActivityData();
                lastLoadTime = zeroTime;
            }catch (Exception e){
                logger.error("reload activityMall error:", e);
            }finally {
                isRun = false;
            }
        }
    }
}
